<%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>角色管理</title>
	<!--[if IE]>
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
	<![endif]-->
	<!-- Main Stylesheet --> 
	<link rel="stylesheet" href="<%=request.getContextPath()%>/css/style.css" type="text/css" />
	<!-- Your Custom Stylesheet --> 
	<link rel="stylesheet" href="<%=request.getContextPath()%>/css/custom.css" type="text/css" />
	<link href="<%=request.getContextPath()%>/lib/thickbox/thickbox.css" rel="stylesheet" type="text/css" />
	<link href="<%=request.getContextPath()%>/lib/jquery/jquery.autocomplete.css" type="text/css" rel="stylesheet"/>
    <style type="text/css">
		#show_area input[type="text"]{
			font-family:宋体;黑体;幼圆;楷体_GB2312;仿宋_GB2312;Arial,Helvetica,sans-serif;
			border:0px;width:100%;height:100;
		}
		.noborder {border:0px none; overflow:auto;}
	</style>
	<%@include file="/include/header.jsp" %>
	<script src="<%=request.getContextPath()%>/lib/jquery/jquery-1.4.2.min.js"></script>
	<script src="<%=request.getContextPath()%>/js/administry.js"></script>
	<script src="<%=request.getContextPath()%>/lib/validator/formValidator_min.js"></script>
	<script src="<%=request.getContextPath()%>/lib/validator/formValidatorRegex.js"></script>
	<script src="<%=request.getContextPath()%>/lib/jquery/jquery.form.js"></script>
	<script src="<%=request.getContextPath()%>/lib/thickbox/thickbox.js"></script>
	<script src="<%=request.getContextPath()%>/lib/jquery/jquery.autocomplete.pack.js"></script>
	<script src="<%=request.getContextPath()%>/js/function.js"></script>
	<script src="<%=request.getContextPath()%>/js/page/pageRender.js"></script>
	<script type="text/javascript">
	function showAddRoleForm(){
		getById("addRole").reset();
		showBox("#TB_inline?height=160&width=500&inlineId=edit_container", "增加角色");
	}
	window.onload = init;
	function init(){
		
		window["pr"] = new PageRender({
			id: 'pr',
			method: 'POST',
			url:'<%=request.getContextPath()%>/protected/system/listRole.action',
			start: <s:property value="start"/>,
			limit: <s:property value="limit"/>,
			total: <s:property value="total"/>,
			data: {
				"roleName" :"#s_roleName",
				"orderby" : "#orderby",
				"locked" : "#locked"
			}
		});
		
		window["pr"].render(getById("page_bar"));
		
	}
	function doSearch(){
		Mask.show();
		window["pr"].position(1);
	}
	$(document).ready(function(){
		Administry.contextBoxInit();
	
		<sec:authorize ifAnyGranted="ADMIN,ROLE_ADD">
		$.formValidator.initConfig({
			formID:"addRole",
			onError:function(msg){
				Alert(msg)
			},
			onSuccess:function(){
				if( confirm("准备提交数据，是否继续？") ){
					Mask.show();
					$('#addRole').ajaxSubmit(Ajax.callback);
				}
				return false;
			}
		});
		$("#roleName").formValidator({
			onShow:"请输入角色名",
			onFocus:"4-30个字符"
		}).inputValidator({min:2,max:30});
		$("#desn").formValidator({
			onShow:"请输入角色描述",
			onFocus:"最多255个字符",
			empty:true
		}).inputValidator({min:0,max:255});
		</sec:authorize>
		
		//AutoComplete角色名关键字输入框
		$("#s_roleName").autocomplete(
		'<%=request.getContextPath()%>/protected/system/autoCompleteRole.action',
		{
			width: 160,
			max: 10,
			scroll: true,
			scrollHeight: 300,
			dataType: 'json',
			matchCase:true,
			parse: function(data) {
				if(!isArray(data)){
					data = eval("("+data+")");
				}
				var rows = [];
				for(var i=0; i<data.length; i++){
					rows.push({
						"data" : data[i],
						"value" : data[i],
						"result" : this.formatResult && this.formatResult(data[i], data[i]) || data[i]
					});
				}
				return rows;
			},
			formatItem: function(data, i, total) {
				return data;
			}
		});
	});
	</script>
</head>
<body style="background-color: #fff;">
	<%@include file="/include/body.jsp" %>
	
<s:if test="flag">
	<!-- 显示操作成功 -->
	<script type="text/javascript">
		showTip("操作成功");
	</script>
</s:if>
<!-- Wrapper -->
<div class="wrapper">
	
    <div class="content-box resizable" id="query_area">
    	<header>
			<h3>搜索</h3>
		</header>
		<section>
		<table class="no-style">
			<tbody>
			<tr>
				<td>
		        	<span>角色名关键字:
		        		<input id="s_roleName" type="text" name="s_roleName" value="<s:property value="roleName"/>" class="input input_wa" />
		        	</span>
		        	
			    	<span>锁定状态：
			    		<s:select id="locked" value="locked"  theme="simple" list="#{'2':'全部','0':'未锁定','1':'锁定'}">
				   		</s:select>
			    	</span>
		            <span>
						<button class="btn" type="submit" onclick="doSearch();"><span class="icon icon-search"></span>搜 索</button>
					</span>
				</td>
			</tr>
			</tbody>
		</table>
		</section>
	</div>
    <div class="content-box" id="show_area">
	<header>
		<h3>
			<span>角色列表</span>
	    	<span>排序：
	    		<s:select id="orderby" value="orderby" onchange="doSearch();" theme="simple" 
		   			list="#{' order by roleName asc':'角色名',' order by createTime asc':'创建时间：升序',' order by createTime desc':'创建时间：降序'}">
		   		</s:select>
	    	</span>
		</h3>
		<div>
	    	<span>
	    		<span>
	    			<a class="btn btn-gray" href="javascript:void(0)" onclick="doSearch();"><span class="icon icon-refresh"></span>刷新</a>
	    		</span>
				<sec:authorize ifAnyGranted="ADMIN,ROLE_ADD">
	    		<span>
	    			<a class="btn" href="javascript:void(0)" onclick="showAddRoleForm();"><span class="icon icon-add"></span>增加角色..</a>
	    		</span>
	   			</sec:authorize>
	    	</span>
	    </div>
    </header>
    <section>
     <table class="display stylized" id="data_table">
     	<thead>
		<tr>
			<th>序号</th><th>角色名</th><th>时间</th>
			<th>描述</th><th>锁定状态</th><th>操作</th>
		</tr>
		</thead>
		<tbody>
		<s:if test="roles != null">
			<s:iterator value="roles" status="rolestatus">
			<form id="form_<s:property value="code"/>" action="<s:url value='editRole.action'></s:url>" method="post">
				<input type="hidden" name="role.code" value="<s:property value="code"/>"/>
				<tr>
					<td><s:property value="#rolestatus.index + 1 + start"/></td>
			 		<td><input type="text" name="role.roleName" value="<s:property value="roleName"/>"/></td>
			 		<td><s:date name="createTime" format="yyyy-MM-dd HH:mm:ss"/></td>
			 		<td><input type="text" name="role.desn" value="<s:property value="desn"/>" /></td>
			 		<td>
			 		<s:if test="#attr.SEC_ISADMIN">
			 		<input type="checkbox" name="role.locked" value="true" <s:if test="locked">checked</s:if>/>
			 		</s:if>
			 		<s:else>
			 		<input type="hidden" name="role.locked" value="<s:property value="locked"/>" />
			 		<s:if test="locked">已锁定</s:if><s:else>未锁定</s:else>
			 		</s:else>
			 		</td>
			 		<td>
			 		<sec:authorize ifAnyGranted="ADMIN,ROLE_UPDATE">
			 			<a href="javascript:void(0);" onclick="if(confirm('请确认')){Mask.show();$('#form_<s:property value="code"/>').ajaxSubmit(Ajax.callback);}">［更新］</a>
			 		</sec:authorize>
			 		<s:if test="! locked">
			 		<sec:authorize ifAnyGranted="ADMIN,ROLE_DELETE">
			 			<a href="javascript:void(0);" onclick="if(confirm('是否删除角色?')){document.location.href='<s:url value='delRole.action?id=%{code}'></s:url>';}">［删除］</a>
			 		</sec:authorize>
			 		</s:if>
			 		</td>
			 	</tr>
			 	</form>
			</s:iterator>
		 </s:if>
		 </tbody>
	</table>
	<div id="page_bar"></div>
	</section>
	</div>
</div>

<sec:authorize ifAnyGranted="ADMIN,ROLE_ADD">
<div id="edit_container" style="display:none;">
 <div id="edit_area">
	<s:form id="addRole" action="addRole.action" method="post">
	<table class="no-style">
		<tr>
			<td><label class="required">角色名</label></td>
			<td><input id="roleName" type="text" name="role.roleName" value=""/></td>
			<td><div id="roleNameTip"></div></td>
		</tr>
		<tr>
			<td><label>描述</label></td>
			<td><input id="desn" type="text" name="role.desn" value=""/></td>
			<td><div id="desnTip"></div></td>
		</tr>
		<s:if test="#attr.SEC_ISADMIN">
		<tr>
			<td><label>锁定</label></td>
			<td><input id="locked" type="checkbox" name="role.locked" value="true"/></td>
			<td><div id="lockedTip"></div></td>
		</tr>
		</s:if>
	</table>
	<div class="form-btn">
		<button class="btn btn-green" type="submit"><span class="icon icon-ok"></span>提 交</button>
		<button class="btn" type="reset" onclick="javascript:tb_remove();"><span class="icon icon-close"></span>取消</button>
	</div>
	</s:form>
</div>
</div>
</sec:authorize>
</body>
</html>